<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .ad {
            width: 200px;
            height: 200px;
            background-color: #aaa;
            position: fixed;
            right: 0;
            bottom: 0;
            padding-left: 20px;

            display: none;
        }

        .close {
            float: right;
            width: 20px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            background-color: #000;
            color: #fff;
            cursor: pointer;
        }
    </style>
</head>

<body>

    <div id="ad" class="ad">
        <span id="c" class="close">X</span>
        <p id="showTime">10s之后关闭</p>
        <h3>我是小广告，请联系我</h3>
    </div>

    <script>

        // 获取这个标签
        var oAd = document.getElementById('ad');
        var oClose = document.getElementById('c');
        var oTime = document.getElementById('showTime');

        // 3s以后出来   setTimeout(fn , 3000)
        fn();
        function fn() {
            setTimeout(function () {
                // 显示小广告
                oAd.style.display = 'block';

                // 小广告显示以后，会出来10s倒计时
                var count = 10;
                oTime.innerHTML = count + 's之后关闭';
                var t = setInterval(function () {
                    count--;
                    oTime.innerHTML = count + 's之后关闭';
                    if (count <= 0) {
                        clearInterval(t);
                        oAd.style.display = 'none';
                        // 3s之后又回来
                        fn()
                    }
                }, 500)

                // 小广告点X也可以关闭
                oClose.onclick = function () {
                    clearInterval(t);
                    oAd.style.display = 'none';
                    // 3s之后又回来
                    fn()
                }
            }, 3000)
        }














        // setInterval(function() {
        //     setTimeout(function () {
        //         // 显示小广告
        //         oAd.style.display = 'block';

        //         // 小广告显示以后，会出来10s倒计时
        //         var count = 10;
        //         oTime.innerHTML = count + 's之后关闭';
        //         var t = setInterval(function () {
        //             count--;
        //             oTime.innerHTML = count + 's之后关闭';
        //             if (count <= 0) {
        //                 clearInterval(t);
        //                 oAd.style.display = 'none';
        //             }
        //         }, 500)

        //         // 小广告点X也可以关闭
        //         oClose.onclick = function () {
        //             clearInterval(t);
        //             oAd.style.display = 'none';
        //             fn()
        //         }
        //     }, 3000)
        // } , 15000)

       

    </script>

</body>

</html>